package com.kordar.datalist;

import lombok.Data;

@Data
public class ResultEntity<T> {
    private Integer code = 0;
    private String msg = "成功";
    private T data;
    private Long count = 0L;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    public ResultEntity() {
    }

    public ResultEntity(T data) {
        this.setData(data);
    }

    public ResultEntity(T data, long count) {
        this.setData(data);
        this.setCount(count);
    }

    public ResultEntity(int code, String msg) {
        this.setCode(code);
        this.setMsg(msg);
    }

    public ResultEntity(int code, String msg, T data) {
        this.setCode(code);
        this.setMsg(msg);
        this.setData(data);
    }

    public ResultEntity(int code, String msg, T data, long count) {
        this.setCode(code);
        this.setMsg(msg);
        this.setData(data);
        this.setCount(count);
    }

    public static<T> ResultEntity<T> success() {
        return new ResultEntity<>();
    }

    public static<T> ResultEntity<T> error(String message) {
        return new ResultEntity<>(1, message);
    }

}
